<%--
  Created by IntelliJ IDEA.
  User: zwb
  Date: 2022/11/1
  Time: 上午8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<link rel="stylesheet" href="./css/index.css">
<head>
    <title>Title</title>

<script src="./js/jquery-3.2.1.js"></script>
</head>
<body>
  <button id="btn">ajax 请求</button>

   <form action="${pageContext.request.contextPath}/fileUpload" method="post" enctype="multipart/form-data">
        <input type="text" name="user" />
        <input type="file" name="fileload">
        <input type="submit" value="上传文件"/>
   </form>


  <form action="${pageContext.request.contextPath}/morefileUpload" method="post"
        enctype="multipart/form-data">
      <input type="text" name="user" />
      <input type="file" name="fileload">
      <input type="file" name="fileload">
      <input type="submit" value="上传文件"/>
  </form>
  <h1>${username}</h1>
</body>
<script>

        $("#btn").click(function (){
            // alert("haha~")
            <%--console.log(${pageContext.request.contextPath});--%>
            let url = '${pageContext.request.contextPath}/ajax';
            let data = '[{"user":"张三","age":"18"},{"user":"张三","age":"24"]';
            $.ajax({
                /*type: get put delete post*/
                type:'POST',
                /* url
                *   json 接受类型的提交List<User>
                * */
                /*提交的数据*/
                data:data,
                url: url,
                /* 提交参数*/
                /*提交内容类型  表单提交 application/x-www-form-urlencoded*/
                contentType:"application/json;charset=utf-8",
                /* 成功回调*/
                success:function(res){
                    console.log(res)
                },
            })
        })

</script>
</html>
